﻿using System.Collections.Generic;
using System.Linq;
using System.IO;

namespace DepSoft.Helpers.iTunes.Elements
{
    public class iTunesPlaylist
    {
        #region Private members
        private string _invalidFileChars = new string(Path.GetInvalidFileNameChars());
        private string _invalidPathChars = new string(Path.GetInvalidPathChars());
        #endregion

        #region Public properties
        /// <summary>
        /// Unique playlist id
        /// </summary>
        public string Id { get; set; }

        /// <summary>
        /// Internal persistant id
        /// </summary>
        public string PlaylistPersistentID { get; set; }

        /// <summary>
        /// Intenal parent persistent id
        /// </summary>
        public string ParentPersistentID { get; set; }

        /// <summary>
        /// Name for the playlist
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// Tracks inside the playlist
        /// </summary>
        public IEnumerable<iTunesTrack> iTunesTracks { get; set; }
        //public List<iTunesTrack> iTunesTracks { get; set; }

        /// <summary>
        /// Get the Parent playlist if available
        /// </summary>
        public iTunesPlaylist Parent { get; set; }

        /// <summary>
        /// Get all the Children playlists if available
        /// </summary>
        //public IEnumerable<iTunesPlaylist> Children { get; set; }
        public List<iTunesPlaylist> Children { get; set; }

        public string ValidPlaylistName
        {
            get
            {
                return new string((from char c in this.Name
                                   select (this._invalidFileChars.Contains(c) ? '-' : c)).ToArray());
            }
        }
        #endregion
    }
}
